package com.songshuai.sales.client.controller;

import com.songshuai.sales.client.service.SaleServiceItemService;
import com.songshuai.webapi.baseapi.dto.pangu.request.service.AddInviteServiceItemReqDto;
import com.songshuai.webapi.baseapi.dto.pangu.request.service.ServiceReqDto;
import com.songshuai.webapi.baseapi.dto.pangu.response.service.InviteServiceItemTreeResDto;
import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import com.songshuai.webapi.baseapi.pojo.QueryResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * @Author: lhx
 * @Date: 2019/4/11 14:26
 */
@Slf4j
@Api("销售-服务标准化")
@RestController
@RequestMapping("/api/sales/service/")
public class SaleServiceItemController extends BaseController {


    @Autowired
    private SaleServiceItemService saleServiceItemService;


    /**
     * 查询所有服务标准化列表
     *
     * @return
     */
    @ApiOperation("查询所有服务标准化列表")
    @GetMapping("getAllServiceList")
    public CompletableFuture<QueryResponse<List<InviteServiceItemTreeResDto>>> getAllServiceList() {
        return CompletableFuture.supplyAsync(() -> saleServiceItemService.getAllServiceList());
    }


    /**
     * 获取邀约服务已反馈信息
     *
     * @param reqDto
     * @return
     */
    @ApiOperation("获取邀约服务已反馈信息")
    @PostMapping("getInviteServiceItems")
    public CompletableFuture<QueryResponse<List<String>>> getInviteServiceItems(@RequestBody ServiceReqDto reqDto) {
        String currentUserId = getCurrentUserId();
        return CompletableFuture.supplyAsync(() -> {
            try {
                if (StringUtils.isNotBlank(currentUserId)) {
                    reqDto.setOperateType(1);
                    reqDto.setOperateId(currentUserId);
                    return saleServiceItemService.getInviteServiceItems(reqDto);
                } else {
                    return new QueryResponse<>(ResultStatus.FAIL);
                }
            } catch (Exception e) {
                log.error("/api/sales/service/getInviteServiceItems", e);
                return new QueryResponse(ResultStatus.ERROR_SEARCH_FAILED.getErrorCode(), e.getMessage());
            }
        });
    }


    /**
     * 新增邀约服务反馈信息
     * @param reqDto
     * @return
     */
    @ApiOperation("新增邀约服务反馈信息")
    @PostMapping("addInviteServiceItem")
    public CompletableFuture<QueryResponse<Boolean>> addInviteServiceItem(@RequestBody AddInviteServiceItemReqDto reqDto) {
        String currentUserId = getCurrentUserId();
        return CompletableFuture.supplyAsync(() -> {
            try {
                if (StringUtils.isNotBlank(currentUserId)) {
                    reqDto.setOperateType(1);
                    reqDto.setOperatorId(currentUserId);
                    return saleServiceItemService.addInviteServiceItem(reqDto);
                } else {
                    return new QueryResponse<>(ResultStatus.FAIL);
                }
            } catch (Exception e) {
                log.error("/api/sales/service/addInviteServiceItem", e);
                return new QueryResponse(ResultStatus.ERROR_SEARCH_FAILED.getErrorCode(), e.getMessage());
            }
        });

    }



}